<?php
// +--------------------------------------------------------------------------
// | ISDCE [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2017 载攸道 版权所有 <TEL:086-010-57209502>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * [ 后台模块 ]
 */
namespace Admin\Controller;
use Common\Controller\AdminController;

/**
 * 用户管理
 */
class UserController extends AdminController{
	
	/*
	 * 用户权限
	 */
	public function Auth(){
	
		action_log('admin_user_auth');//行为记录
		//页面配置
		$page = array(
			
			'title'=>'群组权限',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		
		);
		
		$this->assign('page',$page);
		
		//实例化公共用户群组模型
		$m_common_user_group = M('common_user_group');
		$m_common_user = M('common_user');
		$m_common_menu = M('common_menu');
		
	
		//获得所有菜单
	
		$ammap['id'] = I('param.uid');
		
		
		$amdata  = $m_common_user->where($ammap)->find();
	
	
		$cmmap['status'] =1;
		
		$channel_menu  = $m_common_menu->where($cmmap)->order('sort desc')->select();
		

		//生成相应下级
		foreach($channel_menu as $i=>$k){
			
			$channel_menu_map['fmid'] =  $channel_menu[$i]['id'];
			$channel_menu_map['status'] = 1;
			
			$data_channel_menu = $m_common_menu->where($channel_menu_map)->count();
			
			//判断是否有下级
			if($data_channel_menu != 0){
				
				$channel_menu_map['fmid'] =  $channel_menu[$i]['id'];
				$channel_menu_map['status'] = 1;
				
				$list_data_channel_menu = $m_common_menu->where($channel_menu_map)->select();
				
				foreach($list_data_channel_menu as $il=>$kl){
					
					$cc_channel_menu_map['fmid'] =  $list_data_channel_menu[$i]['id'];
					$cc_channel_menu_map['status'] = 1;
			
					$cc_data_channel_menu = $m_common_menu->where($cc_channel_menu_map)->count();
				}
			}else{
				
				$channel_menu[$i]['top'] = 1;
			}
			
		
		}
		
		
	
		$menu = unserialize($amdata['auth']);
		
		foreach($channel_menu as $i=>$k){
			
			
			foreach($menu as $ii=>$ik){
				
				if($channel_menu[$i]['id']==$menu[$ii]){
					
					
					$channel_menu[$i]['ok'] = 'checked';
					
				}
				
			}
			
			
			
		}
		
		//格式化
		$channel_menu = find_child($channel_menu);
		
		$channel_menu = _findChildren($channel_menu,0);
		
		$this->assign('channel_menu',$channel_menu);
		$this->assign('node_list',$channel_menu);
		
		$this->assign('uid',I('param.uid'));
		$this->assign('amdata',$amdata);
		
		$this->display();

	}
	
	
	/*
	 * 编辑用户权限
	 */
	public function AuthEdit(){
		
		action_log('admin_user_authedit');//行为记录
		
		if(IS_POST){

			$menu = I('param.menu','','');
			$map['id'] = I('param.uid','','');
			
			$data['auth_type'] = I('param.auth_type','','');
			
			$data['auth'] = serialize($menu);
			
			
			$m_common_user= M('common_user');	
			
			$result = $m_common_user->where($map)->save($data);
			
		
			if($result){
				
				 $this->success('授权成功',U('Admin/User/Auth',array('uid' =>$map['id'])));

			}else{

				
				 $this->error('授权失败');
			}

		}else{
			
			//返回信息		
			$info = $info?$info:get_errcode(-2);
	
			$this->ajaxReturn($info);
		}

	}
	
	/*
	 * 用户管理
	 */
    public function Manage(){
		
		action_log('admin_user_manage');//行为记录

		//页面配置
		$page = array(
			
			'title'=>'用户管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		
		);
		
		$this->assign('page',$page);
		
		$m_common_user = M('common_user');
		$m_common_user_group = M('common_user_group');
		$m_common_user_for_group = M('common_user_for_group');
		
	
		
		//用户状态
 		$status_info = array(
		
			'1' 	  => '启用中',
			'2' 	  => '停用中',
			
			
		);
		
		$status = I('param.status');
		if($status!=null){
			
			$map['status']  = $status;
			
		
			$statuss['id'] = $status;
			$statuss['title'] = $status_info[$status];
		
		}else{
			
			$map['status'] = array('neq',0);
	
		}
		
		$this->assign('statuss',$statuss);
		
		
		//判断是否搜索用户名
		$username = I('param.username');
		if($username){
			
			$map['username'] = array('like',"%$username%");

		}
		$this->assign('username',$username);
		
		//判断是否搜索昵称
		$nickname = I('param.nickname');
		if($nickname){
			
			$map['nickname'] = array('like',"%$nickname%");

		}
		$this->assign('nickname',$nickname);
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['id'] =array('like',"%$uid%");
		}
		

		$this->assign('uid',$uid);
		
		//判断是否搜索电话
		$tel = I('param.tel');
		if($tel){
			
			$map['tel'] = array('like',"%$tel%");

		}
		$this->assign('tel',$tel);
		
		//判断是否搜索邮箱
		$email = I('param.email');
		if($email){
			
			$map['email'] = array('like',"%$email%");

		}
		$this->assign('email',$email);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			
			$map['create_time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
			
		}else{
			
			$begin_time=time();
			$end_time=time()+86400;
		}
		
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		//群组信息
		$group = $m_common_user_group->where('status=1')->order('id desc')->select();
		
		$gid= I('param.gid');
		
		
		if($gid!=0){
			
			foreach($group as $gi=>$gk){
				
				if($group[$gi]['id']==$gid){
					
					$group[$gi]['selected'] = "selected";
				}
			}
			
			
			$map['group_id']  = $gid;
			
		}
		
		
		$this->assign('group',$group);
		$this->assign('groups',$group);
		$this->assign('groupss',$group);
		
		
		//默认首页
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_common_user->where($map)->order('status asc,create_time desc')->page($_GET['p'].',20')->select();
		$count      = $m_common_user->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		
		foreach($list as $li=>$lk){

			$ggmap['id'] = $list[$li]['group_id'];
			$ggdata = $m_common_user_group->where($ggmap)->find();

			$list[$li]['group_name'] = $ggdata['name'];
		
			
		}
	
		$this->assign('list',$list);
		
		
		$this->display();
	}
	
	/*
	 * 音乐人管理
	 */
    public function music_manage(){
		
		action_log('admin_user_manage');//行为记录

		//页面配置
		$page = array(
			
			'title'=>'用户管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		
		);
		
		$this->assign('page',$page);
		
		$m_common_user = M('common_user');
		$m_common_user_group = M('common_user_group');
		$m_common_user_for_group = M('common_user_for_group');
		
	
		
		//用户状态
 		$status_info = array(
		
			'1' 	  => '启用中',
			'2' 	  => '停用中',
			
			
		);
		
		$status = I('param.status');
		if($status!=null){
			
			$map['status']  = $status;
			
		
			$statuss['id'] = $status;
			$statuss['title'] = $status_info[$status];
		
		}else{
			
			$map['status'] = array('neq',0);
	
		}
		
		$this->assign('statuss',$statuss);
		
		
		//判断是否搜索用户名
		$username = I('param.username');
		if($username){
			
			$map['username'] = array('like',"%$username%");

		}
		$this->assign('username',$username);
		
		//判断是否搜索昵称
		$nickname = I('param.nickname');
		if($nickname){
			
			$map['nickname'] = array('like',"%$nickname%");

		}
		$this->assign('nickname',$nickname);
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['id'] =array('like',"%$uid%");
		}
		

		$this->assign('uid',$uid);
		
		//判断是否搜索电话
		$tel = I('param.tel');
		if($tel){
			
			$map['tel'] = array('like',"%$tel%");

		}
		$this->assign('tel',$tel);
		
		//判断是否搜索邮箱
		$email = I('param.email');
		if($email){
			
			$map['email'] = array('like',"%$email%");

		}
		$this->assign('email',$email);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['create_time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		//群组信息
		$group = $m_common_user_group->where('status=1')->order('id desc')->select();
		
		$gid= I('param.gid');
		
		
		if($gid!=0){
			
			foreach($group as $gi=>$gk){
				
				if($group[$gi]['id']==$gid){
					
					$group[$gi]['selected'] = "selected";
				}
			}
			
			
			$map['group_id']  = $gid;
			
		}
		
		
		$this->assign('group',$group);
		$this->assign('groups',$group);
		$this->assign('groupss',$group);
		
		$map['group_id']  = 9;
		$map['renling']  = 0;
		//默认首页
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_common_user->where($map)->order('status asc,create_time desc')->page($_GET['p'].',20')->select();
		$count      = $m_common_user->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		
		foreach($list as $li=>$lk){

			$ggmap['id'] = $list[$li]['group_id'];
			$ggdata = $m_common_user_group->where($ggmap)->find();

			$list[$li]['group_name'] = $ggdata['name'];
		
			
		}
	
		$this->assign('list',$list);
		
		$this->display();
	}
	
	/*
	 * 音乐人管理   未认领
	 */
    public function music_manage_ren(){
		
		action_log('admin_user_manage');//行为记录

		//页面配置
		$page = array(
			
			'title'=>'用户管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		
		);
		
		$this->assign('page',$page);
		
		$m_common_user = M('common_user');
		$m_common_user_group = M('common_user_group');
		$m_common_user_for_group = M('common_user_for_group');
		
	
		
		//用户状态
 		$status_info = array(
		
			'1' 	  => '启用中',
			'2' 	  => '停用中',
			
			
		);
		
		$status = I('param.status');
		if($status!=null){
			
			$map['status']  = $status;
			
		
			$statuss['id'] = $status;
			$statuss['title'] = $status_info[$status];
		
		}else{
			
			$map['status'] = array('neq',0);
	
		}
		
		$this->assign('statuss',$statuss);
		
		//判断是否搜索昵称
		$nickname = I('param.nickname');
		if($nickname){
			
			$map['nickname'] = array('like',"%$nickname%");

		}
		$this->assign('nickname',$nickname);
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['id'] =array('like',"%$uid%");
		}
		

		$this->assign('uid',$uid);
		
		//判断是否搜索邮箱
		$email = I('param.email');
		if($email){
			
			$map['email'] = array('like',"%$email%");

		}
		$this->assign('email',$email);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['create_time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		//群组信息
		$group = $m_common_user_group->where('status=1')->order('id desc')->select();
		
		$gid= I('param.gid');
		
		
		if($gid!=0){
			
			foreach($group as $gi=>$gk){
				
				if($group[$gi]['id']==$gid){
					
					$group[$gi]['selected'] = "selected";
				}
			}
			
			
			$map['group_id']  = $gid;
			
		}
		
		
		$this->assign('group',$group);
		$this->assign('groups',$group);
		$this->assign('groupss',$group);
		
		$map['group_id']  = 9;
		$map['renling']  = 1;     //未认领
		//默认首页
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_common_user->where($map)->order('status asc,create_time desc')->page($_GET['p'].',20')->select();
		$count      = $m_common_user->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		
		foreach($list as $li=>$lk){

			$ggmap['id'] = $list[$li]['group_id'];
			$ggdata = $m_common_user_group->where($ggmap)->find();

			$list[$li]['group_name'] = $ggdata['name'];
		
			
		}
	
		$this->assign('list',$list);
		
		$this->display();
	}
	/* 
	*音乐人审核
	*/
	public function music_manage_status(){
		if(IS_AJAX){
				
			$m_common_uers_applys = M('common_uers_applys');
			$m_common_user = M('common_user');
			$id = I('param.id');
			$status = I('param.status');
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					if($status==1){
						#通过后，其他改为不通过
						$save_data['status'] = 1;
						$result = $m_common_uers_applys->where($map)->save($save_data);
						
						if(!empty($result)){
							$data = $m_common_uers_applys->where($map)->find();
							#改变用户信息
							$save_user_map['id'] = $data['form_id'];
							
							$save_user_data['tel'] = $data['tel'];
							$save_user_data['username'] = $data['tel'];
							$save_user_data['password'] = md5($data['password']);
							$save_user_data['card_is'] = $data['card_is'];
							$save_user_data['card_the'] = $data['card_the'];
							$save_user_data['renling'] = 0;
							$m_common_user->where($save_user_map)->save($save_user_data);
							#其他申请改为审核不通过
							$f_map['form_id'] = $map['id'];
							$f_data['status'] = 3;
							$m_common_uers_applys->where($f_map)->save($f_data);
						}
						
					}else if($status==3){
						#修改为不通过
						$save_data['status'] = 3;
						$result = $m_common_uers_applys->where($map)->save($save_data);
					}
				}
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);

	}
	
	
	/*
	 * 音乐人申请管理
	 */
  
    public function music_manage_shen(){
		
		$m_common_uers_applys = M("common_uers_applys");
		$m_common_user = M("common_user");
		
		#判断手机号
		$tel = I('param.tel');
		if($tel){
			$map['tel'] = array('like',"%$tel%");
		}
		$this->assign('tel',$tel);
		#判断状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
		}else{
			$map["status"] = array("neq","0");
		}#判断状态
		$form_id = I('param.form_id');
		if($form_id){
			$map['form_id'] = $form_id;
		}else{
			$map["form_id"] = array("neq","0");
		}
		$this->assign('form_id',$form_id);
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			$begin_time=time();
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$list = $m_common_uers_applys->where($map)->order("")->select();
		foreach($list as $i=>$v){
			$u_map['id'] = $list[$i]['form_id'];
			$u_data = $m_common_user->where($u_map)->find();
			
			$list[$i]['nickname'] = $u_data['nickname'];
			$list[$i]['u_img'] = $u_data['img'];
			
		}
		
		$this->assign("list",$list);
		$this->display();
	} 
	
	
	
	/*
	 * 音乐人管理
	 */
    public function tui_manage(){
		
		action_log('admin_user_manage');//行为记录

		//页面配置
		$page = array(
			
			'title'=>'用户管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		
		);
		
		$this->assign('page',$page);
		
		$m_common_user = M('common_user');
		$m_common_user_group = M('common_user_group');
		$m_common_user_for_group = M('common_user_for_group');
		
	
		
		//用户状态
 		$status_info = array(
			'1' 	  => '启用中',
			'2' 	  => '停用中',
		);
		
		$status = I('param.status');
		if($status!=null){
			
			$map['status']  = $status;
			
		
			$statuss['id'] = $status;
			$statuss['title'] = $status_info[$status];
		
		}else{
			
			$map['status'] = array('neq',0);
	
		}
		
		$this->assign('statuss',$statuss);
		
		
		//判断是否搜索用户名
		$username = I('param.username');
		if($username){
			
			$map['username'] = array('like',"%$username%");

		}
		$this->assign('username',$username);
		
		//判断是否搜索昵称
		$nickname = I('param.nickname');
		if($nickname){
			
			$map['nickname'] = array('like',"%$nickname%");

		}
		$this->assign('nickname',$nickname);
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['id'] =array('like',"%$uid%");
		}
		

		$this->assign('uid',$uid);
		
		//判断是否搜索电话
		$tel = I('param.tel');
		if($tel){
			
			$map['tel'] = array('like',"%$tel%");

		}
		$this->assign('tel',$tel);
		
		//判断是否搜索邮箱
		$email = I('param.email');
		if($email){
			
			$map['email'] = array('like',"%$email%");

		}
		$this->assign('email',$email);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			
			$map['create_time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
			
		}else{
			
			$begin_time=time();
			$end_time=time()+86400;
		}
		
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		
		$map['recommended']  = 1;
		$map['group_id']  = 9;
		//默认首页
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_common_user->where($map)->order('status asc,create_time desc')->page($_GET['p'].',20')->select();
		$count      = $m_common_user->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		
		foreach($list as $li=>$lk){

			$ggmap['id'] = $list[$li]['group_id'];
			$ggdata = $m_common_user_group->where($ggmap)->find();

			$list[$li]['group_name'] = $ggdata['name'];
		
			
		}
	
		$this->assign('list',$list);
		
		
		$this->display();
	}
	
	/* 排序单曲推荐位置 */
	public function r_activity(){
		$m_common_user = M('common_user');
		if(IS_AJAX){
			
			$map['id'] = I("param.id");
			$data['sort'] = I("param.sort");
			if(!empty($map['id'])){
				$result = $m_common_user->where($map)->save($data);
				if($result){
					$info = 1;
				}else{
					$info = 2;
				}
			}else{
				$info = 3;
			}
			
		}else{
			$info = 4;
		}
		$this->ajaxReturn($info);
	}
	
	
	/* 排序单曲推荐位置---PM */
	public function pm_activity(){
		$m_common_user = M('common_user');
		if(IS_AJAX){
			
			$map['id'] = I("param.id");
			$data['pm_sort'] = I("param.sort");
			if(!empty($map['id'])){
				$result = $m_common_user->where($map)->save($data);
				if($result){
					$info = 1;
				}else{
					$info = 2;
				}
			}else{
				$info = 3;
			}
			
		}else{
			$info = 4;
		}
		$this->ajaxReturn($info);
	}
	
	/* 排序单曲推荐位置---PM */
	public function cz_activity(){
		$m_common_user = M('common_user');
		if(IS_AJAX){
			
			$map['id'] = I("param.id");
			$data['cz_sort'] = I("param.sort");
			if(!empty($map['id'])){
				$result = $m_common_user->where($map)->save($data);
				if($result){
					$info = 1;
				}else{
					$info = 2;
				}
			}else{
				$info = 3;
			}
			
		}else{
			$info = 4;
		}
		$this->ajaxReturn($info);
	}
	
	
	#加入推荐
	public function recommended($id,$recommended=0){
		//判断是否是ajax请求
		if(IS_AJAX){
			$m_common_user = M('common_user');
			
			$id = $id?$id:I('param.id');
			$recommended= $recommended?$recommended:I('param.recommended');
			
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data_data = $m_common_user->where($map)->find();
					if($data_data['status'] == 1){
						$data['recommended'] = $recommended;
						$m_common_user->where($map)->save($data);
					}
					
				}
				
				//返回信息
				$info = get_errcode(0);
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
		
	}
	
	/*
	 * 新增音乐人
	 */
    public function Create(){
		$m_common_user = M('common_user');
		$m_common_user_group = M('common_user_group');
		$m_common_user_country = M('common_user_country');
		$m_mall_content = M('mall_content');
						
		if(IS_AJAX){
			$data = I('');
			
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['style'] ="1,2";
			
			if($data['agreement_id'] == 0 or $data['agreement_id'] == 1){
				unset($data['agreement']);
			}
			
			$data['password'] = md5(I('param.password'));
			if($data['username'] == ''){
				$data['username'] = time().rand(0,99).rand(0,9);
			}
			$data['password'] = md5(I('param.password'));
			$data['create_time'] = time();
			$data['create_ip'] = get_client_ip();
			$data['group_id'] = I('param.group_id'); //默认群组TODO动态配置
			$data['status'] = 1;
			$result = $m_common_user->add($data);
			
			if($result){
				add_style(5,$result,$style);
			}
			//返回信息 TODO判断错误原因
			$info = $result?get_errcode(0):get_errcode(10000004);
			
			$this->ajaxReturn($info);
			
		}else{
			
			action_log('admin_user_create_view');//行为记录
		
			//页面配置
			$page = array(
				
				'title'=>'新增用户',
				'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'author'=>'YiPHP',
				'robots' => 'all',
			);
			$country_list = $m_common_user_country->order("id asc")->select();
			
			#风格
			$style_maps['type'] = get_mall_model_conf('MALL_STYLE');
			$style_maps['status'] = 1;
			$style_list = $m_mall_content->where($style_maps)->order('sort desc')->select();
			$this->assign('style_list',$style_list);
			
			$this->assign('country_list',$country_list);
			$this->assign('page',$page);
			
			$this->display();
		}
		
		
	}
	
	/*
	 * 新增用户
	 */
    public function Create_user(){
		$m_common_user = M('common_user');
		$m_common_user_group = M('common_user_group');
		$m_common_user_country = M('common_user_country');
		$m_mall_content = M('mall_content');
						
		if(IS_AJAX){
			$data = I('');
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			if($data['agreement_id'] == 0 or $data['agreement_id'] == 1){
				unset($data['agreement']);
			}
			$data['password'] = md5(I("param.password")); //默认密码TODO动态配置
			$data['create_time'] = time();
			$data['create_ip'] = get_client_ip();
			$data['group_id'] = 3; //默认群组TODO动态配置
			$data['status'] = 1;
			if($data['tel'] == ''){
				$data['renling'] = 1;    //1未认领
			}
			
			$result = $m_common_user->add($data);
			
			if($result){
				add_style(5,$result,$style);
			}
			//返回信息 TODO判断错误原因
			$info = $result?get_errcode(0):get_errcode(10000004);
			$this->ajaxReturn($info);
			
		}else{
			
			action_log('admin_user_create_view');//行为记录
			
			//页面配置
			$page = array(
				
				'title'=>'新增用户',
				'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'author'=>'YiPHP',
				'robots' => 'all',
			);
			$country_list = $m_common_user_country->order("id asc")->select();
			
			#风格
			$style_maps['type'] = get_mall_model_conf('MALL_STYLE');
			$style_maps['status'] = 1;
			$style_list = $m_mall_content->where($style_maps)->order('sort desc')->select();
			$this->assign('style_list',$style_list);
			
			$this->assign('country_list',$country_list);
			$this->assign('page',$page);
			
			$this->display();
		}
		
		
	}
	
	/*
	 * 修改用户
	 */
    public function Edit(){
		
		$m_common_user = M('common_user');
		$m_mall_content = M('mall_content');
		$m_common_user_country = M('common_user_country');
			
		$map['id'] = I('param.id');
			
		if(IS_AJAX){
			
			$data = I('');
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			unset($data['id']);
			if($data['agreement_id'] == 0 or $data['agreement_id'] == 1){
				unset($data['agreement']);
			}
			$result = $m_common_user->where($map)->save($data);
			if($result){
				add_style(5,$map['id'],$style);
			}
			//返回信息 TODO判断错误原因
			$info = $result?get_errcode(0):get_errcode(10000002);
			
			$this->ajaxReturn($info);
			
		}else{
			
			action_log('admin_user_edit_view');//行为记录
			
			//页面配置
			$page = array(
				
				'title'=>'修改信息',
				'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'author'=>'YiPHP',
				'robots' => 'all',
			
			);
			
			$this->assign('page',$page);
			
			$data = $m_common_user->where($map)->find();
			
			$this->assign('data',$data);
			$country_list = $m_common_user_country->order("id asc")->select();
			
			#风格
			$style_maps['type'] = get_mall_model_conf('MALL_STYLE');
			$style_maps['status'] = 1;
			$style_list = $m_mall_content->where($style_maps)->order('sort desc')->select();
			$style_list = if_style($style_list,$data['style']);
			$this->assign('style_list',$style_list);
			
			$this->assign('country_list',$country_list);
			
			
			
			$this->display();
		}
		
		
	}
	
	/*
	 * 改变用户信息
	 */
	public function Status($id,$status=0){
		
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_common_user = M('common_user');
			
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			
			if($id){
				
			
				$id = explode(',',$id); 
				
				
				foreach($id as $i=>$k){
					
					$map['id'] = $id[$i];
					
					if($status==3){
						
						action_log('admin_user_status_password');//行为记录
		
						$data['password'] = md5('123123q'); //TODO动态配置密码
			
						$m_common_user->where($map)->save($data);
						
					}else{
						
						//启用或者停用用户
						if($status==1){
							
							action_log('admin_user_status_enabled');//行为记录
						
						}else{
							
							action_log('admin_user_status_outage');//行为记录
						
						}
						
						$data['status'] = $status;
			
						$m_common_user->where($map)->save($data);
					
					}
					
					
					
				}
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
			
	
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);


	}
	
	/*
	 * 关联用户群组
	 */
	public function Relevance(){
		
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_common_user = M('common_user');
			
			$map['id'] = I('param.uid');
			
			$data['group_id'] = I('param.group');

			$result = $m_common_user->where($map)->save($data);
			
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
				
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	
	/*
	 * 关联用户群组
	 */
	public function Login(){
		
		if(getUID()==1){
			
			//统一登录接口
			login(I('param.id'));
			
			//获得跳转着陆页
			$url = getLoginURL(I('param.id'));
		
			//跳转到着陆页
			$this->success('登录成功',U($url['url']));
			
		}else{
			
			  $this->error('登录失败');
			
		}
		
	}
	
	
}